// JavaScript Document

	$(document).ready(function() {
		
		//Set all password field empty
		//$("#password").val('');
		
		/*** Message timeout ***/
		setTimeout(function(){
			$("#flashMessage").fadeOut("slow", function () {
				$("#flashMessage").remove()
				;})
			;}, 
			3000);
		
		
		/*** Click test to open input file in Check Word ***/
		var wrapper = $('<div/>').css({height:0,width:0,'overflow':'hidden'});
		var fileInput = $(':file').wrap(wrapper);

		fileInput.change(function(){
			$this = $(this);
			$('#file').text($this.val());
		})
		
		$('#file').click(function(){
			fileInput.click();
		}).show();

		
		/*** Word Check function - Check type of the file upload to check word ***/
		$('#sb_upload').click(function(){	
			$('#upload_file_check_word').validate({
		        rules: {
		            'data[MAvoidanceWord][file_name]': {
		                required: true,
		                extension: "txt"
		            },
		        },
		        invalidHandler: function(){
		        	alert("Please choose text(.txt) file");
		        },
		        submitHandler: function (form) {
		            form.submit();
		        }
		    });
		});	
		
		/*** Word Check function - Check type of the file upload to import ***/
		$('#upload_file').validate({
	        rules: {
	            'data[MAvoidanceWord][file_name]': {
	                required: true,
	                extension: "csv"
	            },
	        },
	        invalidHandler: function(){
	        	alert("Please choose CSV file");
	        },
	        submitHandler: function (form) {
	        	//For Word List
	    		if($('#sb_upload_word').val() != null){
	            	var filename = $('input[type=file]').val().split('\\').pop();
	            	if(filename.match(/^[w]{1}[o]{1}[r]{1}[d]{1}[l]{1}[i]{1}[s]{1}[t]{1}[_]{1}[0-9]{14}$/)){
	            		form.submit();
	    			}
	            	else
	            		alert("Warning ! You didn't choose CSV for Avoidance Word List");
	    		};
	    		//For User List
	    		if($('#sb_upload_user').val() != null){
	            	var filename = $('input[type=file]').val().split('\\').pop();
	            	if(filename.match(/^[u]{1}[s]{1}[e]{1}[r]{1}[l]{1}[i]{1}[s]{1}[t]{1}[_]{1}[0-9]{14}$/)){
	            		form.submit();
	    			}
	            	else
	            		alert("Warning ! You didn't choose CSV for User List");
	    		};
	        }
	    });


	
		
		
    
    });// End ready
	